package omq.samples;

import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import omq.api.*;

/*
 *  OMQ Sample Codes:
 *  -----------------
 * 
 *  CheckConnection demonstrates the use of the CheckConnection method from OMQ API which verifies that:
 *  	- a connection can be established to the OMQ server
 *  	- user name exists and password match
 *  	- queue manager exists
 *  	- queue exists
 *  
 *  It uses SOAP to establish connection with the server.
 *  
 *  You can experiment with user, password, queue-manager and queue names to see what response code you're getting from OMQ.
 *  
 *  Author  	  	: Hagai Izenberg
 *  Creating Date 	: 02-11-2008
 *  Company 		: OMQI
 */

public class CheckConnection {

	public static void main(String[] args) throws ServiceException, RemoteException
	{
		String omqUser = "demo-superadmin";
		String omqPassword = "demokopp";
		String omqQueueManager = "bank";
		String omqQueue = "q1";
		
		OMQConnection con = OMQConnectionFactory.getConnection(omqUser,omqPassword, new OMQQueueManager(omqQueueManager));

		System.out.println("checking connection...");
		
		int rc = con.checkConnection(new OMQQueue(omqQueue));
		if (rc == 0)
		{
			System.out.println("connection initiated successfully");
		}
		else if (rc == 101) // example for handling specific error code 101 = Authentication failed 
		{
			System.out.println("Authentication failed...");
		}
		else
		{
			System.err.println("connection check failed");
		}
		
		System.out.println("LastErrorCode()="+con.getLastErrorCode()+", LastErrorDescription()="+con.getLastErrorDescription());
		
		/*
		 * check 
		 * http://www.onlinemq.com/support/index.php/Online_MQ_API#Error_handling 
		 * for a list of error codeS
		 */ 	
	}

}
